package com.fi.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fi.common.domain.entity.ResAccessoryFileInfo;
import com.fi.common.mapper.ResAccessoryFileInfoMapper;
import com.fi.common.service.ResAccessoryFileInfoLabelService;
import com.fi.common.service.ResAccessoryFileInfoService;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author songqiang
 * @desc 对公告服务类的扩展类，用于将拆分的标签在获取时组装到公告上面
 * @created on 2023 年 09 月 11
 * @Date 15:13
 * @since 1.0
 */
public abstract class ResAccessoryFileServiceImplExt extends ServiceImpl<ResAccessoryFileInfoMapper, ResAccessoryFileInfo> implements ResAccessoryFileInfoService {

    @Resource
    private ResAccessoryFileInfoLabelService resAccessoryFileInfoLabelService;


    @Override
    public List<ResAccessoryFileInfo> listByIds(Collection<? extends Serializable> idList) {
        List<ResAccessoryFileInfo> resAccessoryFileInfos = super.listByIds(idList);
        if (resAccessoryFileInfos.isEmpty()) {
            return resAccessoryFileInfos;
        }
        resAccessoryFileInfoLabelService.assembleFileInfoLabel(resAccessoryFileInfos);
        return resAccessoryFileInfos;
    }

    @Override
    public ResAccessoryFileInfo getById(Serializable id) {
        ResAccessoryFileInfo obj = super.getById(id);
        if (Objects.isNull(obj)) {
            return null;
        }
        resAccessoryFileInfoLabelService.assembleFileInfoLabel(Collections.singletonList(obj));
        return obj;
    }

    @Override
    public ResAccessoryFileInfo getOne(Wrapper<ResAccessoryFileInfo> queryWrapper) {
        ResAccessoryFileInfo obj = super.getOne(queryWrapper);
        if (Objects.isNull(obj)) {
            return null;
        }
        resAccessoryFileInfoLabelService.assembleFileInfoLabel(Collections.singletonList(obj));
        return obj;
    }

    @Override
    public List<ResAccessoryFileInfo> list() {
        List<ResAccessoryFileInfo> accessoryFileInfos = super.list();
        resAccessoryFileInfoLabelService.assembleFileInfoLabel(accessoryFileInfos);
        return accessoryFileInfos;
    }

    @Override
    public List<ResAccessoryFileInfo> list(Wrapper<ResAccessoryFileInfo> queryWrapper) {
        List<ResAccessoryFileInfo> accessoryFileInfos = super.list(queryWrapper);
        resAccessoryFileInfoLabelService.assembleFileInfoLabel(accessoryFileInfos);
        return accessoryFileInfos;
    }

    @Override
    public boolean removeByIds(Collection<?> list) {
        resAccessoryFileInfoLabelService.removeByIds(list);
        return super.removeByIds(list);
    }

    @Override
    public boolean removeById(ResAccessoryFileInfo entity) {
        resAccessoryFileInfoLabelService.removeById(entity.getId());
        return super.removeById(entity);
    }

    @Override
    public boolean removeBatchByIds(Collection<?> list) {
        resAccessoryFileInfoLabelService.removeBatchByIds(list);
        return super.removeBatchByIds(list);
    }
}
